package com.qhnu.zxjx.controller;

import com.qhnu.zxjx.annotation.RequestLog;
import com.qhnu.zxjx.model.response.Response;
import com.qhnu.zxjx.model.vo.LoginVo;
import com.qhnu.zxjx.model.vo.RegisterVo;
import com.qhnu.zxjx.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @program: zxjx
 * @author: liudanqing
 * @description 用户相关接口
 * @create: 2019-11-17 13:40
 **/
@Api(tags = "用户模块")
@RestController
@RequestMapping(value = "/user")
@Validated
public class UserController {

    @Autowired
    private IUserService userService;

    /*@RequestMapping(value = "/register/{userName}/{pwd}/{Yqcode}")
    @ResponseBody
    public HashMap<String,String> register(@PathVariable(value = "userName",required = true) String userName,
                                           @PathVariable(value = "pwd",required = true) String pwd,
                                           @PathVariable(value = "Yqcode",required = true) String yqCode){
        HashMap<String,String> modelMap = new HashMap<String,String>();

        if(yqCode.equals("0")){
            modelMap.put("status","wait");
        }else{
            //查邀请码
            if(this.userService.countYqcode(new HashMap<String,Object>(){
                {
                    put("yqCode",yqCode);
                }
            }) >= 1){
                //增加用户
                userService.insertUser(new HashMap<String,Object>(){
                    {
                        put("userName",userName);
                        put("pwd",pwd);
                    }
                });
                modelMap.put("status", "success");

            }else {
                modelMap.put("status", "error");
            }
        }


        return modelMap;
    }*/

    @ApiOperation(value = "用户注册")
    @PostMapping(value = "/register")
    @RequestLog
    public Response register(@RequestBody @Valid RegisterVo registerVo) {
        userService.register(registerVo);
        return new Response();
    }
}
